<template>
	<view>
		<u-navbar back-text="我的订单" title=""></u-navbar>
		<view class="wrap">
			<view class="u-tabs-box">
				<u-tabs activeColor="#FF365D" ref="tabs" :list="listTab" :current="current" @change="change"
					:is-scroll="false" swiperWidth="750"></u-tabs>
			</view>
			<u-empty v-if="list.length==0"></u-empty>
			<view class="" style="width: 100%;" v-else>
				<GoodsItem @delOrderInfo='delOrderInfo' @handleRefund='handleRefund' @handleComment='handleComment'
					@handleReceiving='handleReceiving' @handlePay='handlePay' @handDetailsNavTo='handDetailsNavTo'
					@turnShop='turnShop' v-for="item in list" :key='item.id' :item='item' @handlecancel='handlecancel'>
				</GoodsItem>
				<u-loadmore :status="status" />
			</view>

		</view>
	</view>
</template>

<script>
	import initData from '@/mixin/initData.js'
	import GoodsItem from './components/OrderGoodsItem-2.vue'
	export default {
		mixins: [initData],
		components: {
			GoodsItem
		},
		data() {
			return {

				listTab: [{
						name: '全部',
					}, {
						name: '待付款'
					},
					{
						name: '待发货'
					},
					{
						name: '待收货'
					}

				],
				current: 0,
			};
		},
		onBackPress() {
			// 解决从订单页跳转过来之后 无法返回问题
			uni.switchTab({
				url: '/pages/my/my'
			})
			return true;
		},
		onLoad(e) {

			if (e.current != undefined && e.current != 'null') {
				this.current = Number(e.current) + 1
			}
			this.miXinInit()
		},
		computed: {

		},
		methods: {
			handleAfterSale(item) {
				uni.navigateTo({
					url: '/pages/afterSale/afterSaleDetails/afterSaleDetails?id=' + item.id
				})
			},
			handleRefund(item) {
				uni.navigateTo({
					url: '/pages/refund/refund?order=' + JSON.stringify(item)
				})
			},
			handleComment(item) {
				uni.navigateTo({
					url: '/pages/handleComment/handleComment?order=' + JSON.stringify(item)
				})
			},
			handleReceiving(item) {
				const that = this
				uni.showModal({
					title: '提示',
					content: '确认您的订单已完成',
					success(res) {
						if (res.confirm) {
							that.$u.api.confirmReceipt({
								id: item.id
							}).then(res => {
								uni.showToast({
									title: '确认收货成功',

									icon: 'none'
								})
								that.toReset()
								that.miXinInit()
							})
						}

					}
				})
			},
			delOrderInfo(item) {
				const that = this
				uni.showModal({
					title: '提示',
					content: '确认删除吗?',
					success(res) {
						if (res.confirm) {
							that.$u.api.delOrderInfoById({
								id: item.id
							}).then(res => {
								uni.showToast({
									title: '删除成功',

									icon: 'none'
								})
								that.toReset()
								that.miXinInit()
							})
						}

					}
				})
			},
			handlePay(item) {

				uni.navigateTo({
					url: '/pages/payPages/payPages?order=' + JSON.stringify(item)
				})

			},
			handDetailsNavTo(item) {
				uni.navigateTo({
					url: '/pages/order/orderDetail/orderDetail?id=' + item.id
				})
			},
			turnShop(item) {
				uni.showModal({
					title: '提示',
					content: '确认转给商家吗?',
					success(res) {
						if (res.confirm) {
							uni.navigateTo({
								url: '/pages/selfPoint/selfPoint?id=' + item.id
							})
						}

					}
				})
			},
			handlecancel(row) {
				console.log(row, '====')
				const that = this
				uni.showModal({
					title: '提示',
					content: '确认取消吗?',
					success(res) {
						if (res.confirm) {
							that.$u.api.cancellationOrder({
								id: row.id,
								refundAmount: row.totalMoney
							}).then(res => {
								uni.showToast({
									title: '取消成功',
									icon: 'none'
								})
								that.toReset()
								that.miXinInit()
							})
						}

					}
				})
			},
			// 请求前的参数处理
			beforeInit() {
				this.apiUrl = "orderInfo/getOrderInfoList";
				let params = {
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					status: this.current + 1 || 0 //1全部 2待付款 3待发货 4待收货
				};

				this.params = {
					...params
				};
			},
			handNavTo() {
				uni.navigateTo({
					url: '/pages/order/orderDetail/orderDetail'
				})
			},

			// tab栏切换
			change(index) {
				this.current = index;
				this.toReset()
				this.miXinInit()
			},

		}
	};
</script>

<style>
	/* #ifndef H5 */
	page {
		height: 100%;
		background-color: #f2f2f2;
		/* min-height: 100vh; */
	}

	/* #endif */
</style>

<style lang="scss" scoped>

</style>
